<template>
  <el-card class="box-card" style="margin: 10px 0px">
    <div slot="header" class="clearfix">
      <!--  @tab-click="handleClick" -->
      <!-- 头部左侧内容 -->
      <el-tabs class="tab" v-model="activeName">
        <el-tab-pane label="销售额" name="sale"></el-tab-pane>
      </el-tabs>
      <!-- 头部右侧内容 -->
      <div class="right">
        <span @click="setDay">今日</span>
        <span @click="setWeek">本周</span>
        <span @click="setMonth">本月</span>
        <span @click="setYear">本年</span>
        <!--    v-model="value1" -->
        <el-date-picker v-model="date" class="date" type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd"> </el-date-picker>
      </div>
    </div>
    <div>
      <el-row :gutter="10">
        <el-col :span="18">
          <!-- 容器 -->
          <div class="charts" ref="charts"></div>
        </el-col>
        <el-col :span="6" class="right">
          <h3>景点销售额排名</h3>
          <ul>
            <li>
              <span class="rindex">1</span>
              <span>故宫</span>
              <span class="rvalue">923456</span>
            </li>
            <li>
              <span class="rindex">2</span>
              <span>颐和园</span>
              <span class="rvalue">823456</span>
            </li>
            <li>
              <span class="rindex">3</span>
              <span>八达岭</span>
              <span class="rvalue">723456</span>
            </li>
            <li>
              <span>4</span>
              <span>黄山</span>
              <span class="rvalue">623456</span>
            </li>
            <li>
              <span>5</span>
              <span>夫子庙</span>
              <span class="rvalue">523456</span>
            </li>
            <li>
              <span>6</span>
              <span>广州长隆</span>
              <span class="rvalue">423456</span>
            </li>
            <li>
              <span>7</span>
              <span>深圳欢乐谷</span>
              <span class="rvalue">323456</span>
            </li>
          </ul>
        </el-col>
      </el-row>
    </div>
  </el-card>
</template>

<script>
//引入echarts
import * as echarts from 'echarts'
import dayjs from 'dayjs'
// import { mapState } from "vuex";
export default {
  name: '',
  data() {
    return {
      activeName: 'sale',
      // mycharts: null,
      //收集日历数据
      date: [],
    }
  },
  mounted() {
    // 解决echarts网页加载完无法显示
    this.$nextTick(() => {
      setTimeout(() => {
        this.creMyCharts()
      }, 0)
    })
  },
  methods: {
    creMyCharts() {
      let mycharts = echarts.init(this.$refs.charts)
      //配置数据
      mycharts.setOption({
        title: {
          text: '销售趋势',
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'shadow',
          },
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true,
        },
        xAxis: [
          {
            type: 'category',
            data: ['一月', '二月', '三月', '四月', '五月', '六月', '七月','八月','九月','十月','十一月','十二月'],
            axisTick: {
              alignWithLabel: true,
            },
          },
        ],
        yAxis: [
          {
            type: 'value',
          },
        ],
        series: [
          {
            name: 'Direct',
            type: 'bar',
            barWidth: '60%',
            color:'#f47920',
            data: [809876, 209876, 269876, 969876, 769876, 469876, 1069876,149876,339876,569876,444876,239876],
          },
        ],
      })
    },
    //本天
    setDay() {
      const day = dayjs().format('YYYY-MM-DD')
      this.date = [day, day]
    },
    //本周
    setWeek() {
      const start = dayjs().day(1).format('YYYY-MM-DD')
      const end = dayjs().day(7).format('YYYY-MM-DD')
      this.date = [start, end]
    },
    //本月
    setMonth() {
      const start = dayjs().startOf('month').format('YYYY-MM-DD')
      const end = dayjs().endOf('month').format('YYYY-MM-DD')
      this.date = [start, end]
    },
    //本年
    setYear() {
      const start = dayjs().startOf('year').format('YYYY-MM-DD')
      const end = dayjs().endOf('year').format('YYYY-MM-DD')
      this.date = [start, end]
    },
  },
}
</script>

<style scoped>
.clearfix {
  position: relative;
  display: flex;
  justify-content: space-between;
}
.tab {
  width: 100%;
}
.right {
  position: absolute;
  right: 0px;
}
.date {
  width: 250px;
  margin: 0px 20px;
}
.right span {
  margin: 0px 10px;
}
.charts {
  width: 100%;
  height: 300px;
}
ul {
  list-style: none;
  width: 100%;
  height: 300px;
  padding: 0px;
}
ul li {
  height: 8%;
  margin: 10px 0px;
}
.rindex {
  float: left;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: black;
  color: white;
  text-align: center;
}
.rvalue {
  float: right;
}
</style>
